//
//  MessageTableViewCell.m
//  UEAssistant
//
//  Created by mac on 2017/3/3.
//  Copyright © 2017年 youyixinxi. All rights reserved.
//

#import "MessageTableViewCell.h"
#import "MessageModel.h"

NSString *messageTableViewCell = @"messageTableViewCell_YHX";

@implementation MessageTableViewCell

+ (instancetype)cellWithTableview:(UITableView *)tableview{

    MessageTableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:messageTableViewCell];
    cell.backgroundColor = [UIColor whiteColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}


- (void)setModel:(MessageModel *)model{
    
    _model = model;
    
    [_headView sd_setImageWithURL:[NSURL URLWithString:shareData.headURL] placeholderImage:[UIImage imageNamed:@"user"]];
    _timeLabel.text = [[self stringFromDate:[self dateFromLongLong:[_model.createDate longLongValue]]] substringToIndex:19];
    _MessageSender.text = model.from_username;
    
    _msaLabel.numberOfLines = 0;
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.alignment = NSTextAlignmentLeft;
    paraStyle.lineSpacing = 5.0f;//行间距
    NSMutableArray *arr = [NSMutableArray arrayWithArray:[model.content componentsSeparatedByString:@"，"]];
    [arr removeLastObject];
    NSString *str = [arr componentsJoinedByString:@"，"];
    NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:str attributes:@{NSParagraphStyleAttributeName:paraStyle}];
    _msaLabel.attributedText = attrText;
    
}

//时间转换
- (NSDate*)dateFromLongLong:(long long)msSince1970{
    
    return [NSDate dateWithTimeIntervalSince1970:msSince1970 / 1000];
}

- (NSString*)stringFromDate:(NSDate*)date{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss zzz"];
    return [dateFormatter stringFromDate:date];
}




- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end

